package com.canaan.business.controller.pc.basic;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.canaan.business.domain.basic.WmsProduct;
import com.canaan.business.domain.vo.ProductStockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.basic.ErpProduct;
import com.canaan.business.service.basic.IErpProductService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * ERP物料主数据Controller
 *
 * @author canaan
 * @date 2025-03-23
 */
@Api(tags = "ERP物料主数据")
@RestController
@RequestMapping("/basic/erpProduct")
public class ErpProductController extends BaseController {
    @Resource
    private IErpProductService erpProductService;

    /**
     * 查询ERP物料主数据列表
     */
    @ApiOperation(value = "查询ERP物料主数据列表")
    @GetMapping("/list")
    public TableDataInfo list(ErpProduct erpProduct) {
        startPage();
        List<ErpProduct> list = erpProductService.selectErpProductList(erpProduct);
        return getDataTable(list);
    }

    /**
     * 导出ERP物料主数据列表
     */
    @ApiOperation(value = "导出ERP物料主数据列表")
    @Log(title = "ERP物料主数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpProduct erpProduct) {
        List<ErpProduct> list = erpProductService.selectErpProductList(erpProduct);
        ExcelUtil<ErpProduct> util = new ExcelUtil<ErpProduct>(ErpProduct.class);
        util.exportExcel(response, list, "ERP物料主数据数据");
    }

    /**
     * 获取ERP物料主数据详细信息
     */
    @ApiOperation(value = "获取ERP物料主数据详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(erpProductService.selectErpProductById(id));
    }

    /**
     * 新增ERP物料主数据
     */
    @ApiOperation(value = "新增ERP物料主数据")
    @Log(title = "ERP物料主数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpProduct erpProduct) {
        return toAjax(erpProductService.insertErpProduct(erpProduct));
    }

    /**
     * 修改ERP物料主数据
     */
    @ApiOperation(value = "修改ERP物料主数据")
    @Log(title = "ERP物料主数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpProduct erpProduct) {
        return toAjax(erpProductService.updateErpProduct(erpProduct));
    }

    /**
     * 删除ERP物料主数据
     */
    @ApiOperation(value = "删除ERP物料主数据")
    @Log(title = "ERP物料主数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(erpProductService.deleteErpProductByIds(ids));
    }

    /**
     * 根据物料编号获取物料主数据详细信息
     */
    @ApiOperation(value = "根据物料编号获取物料主数据详细信息")
    @GetMapping(value = "/getByProductNo/{productNo}")
    public AjaxResult getInfoByProductNo(@PathVariable("productNo") String productNo) {
        String no;
        if (StrUtil.isNotEmpty(productNo)) {
            no = StrUtil.trim(productNo);
        } else {
            no = productNo;
        }
        return success(erpProductService.selectErpProductByProductNo(no));
    }
    /**
     * 通过仓库查询物料主数据列表
     */
    @ApiOperation("通过仓库查询物料主数据列表")
    @GetMapping("/listByStorehouseNo")
    public TableDataInfo listByStorehouseNo(ErpProduct erpProduct) {
        startPage();
        List<ErpProduct> list = erpProductService.listByStorehouseNo(erpProduct);
        return getDataTable(list);
    }
}
